import math
from time import time

from numba import cuda

def cpu_print(N):
    for idx in range(0, N):
        if Prime1(idx) == True and Prime1(idx + 2) == True:
            continue


def Prime1(n):
    k = int(math.sqrt(n))
    if n < 2:
        return False
    elif n == 2:
        return True
    else:
        i = 2
        for i in range(2, k + 2):
            if n % i == 0:
                break
            else:
                i = i + 1
        if i == k + 2:
            return True
        else:
            return False


@cuda.jit
def Prime(n):
    k = int(math.sqrt(n))
    if n < 2:
        return False
    elif n == 2:
        return True
    else:
        i = 2
        for i in range(2, k + 2):
            if n % i == 0:
                break
            else:
                i = i + 1
        if i == k + 2:
            return True
        else:
            return False

@cuda.jit
def gpu_print(N):
    idx = cuda.threadIdx.x + cuda.blockIdx.x * cuda.blockDim.x
    if (idx < N):
        if Prime(idx) == True and Prime(idx + 2) == True:
            print(idx, idx + 2)


def main():
    print("gpu print:")
    start_gpu = time()
    gpu_print[10**6, 1024](10**7)

    cuda.synchronize()
    print("gpu vector add time " + str(time() - start_gpu))
   # print("cpu print:")
    # start_cpu = time()
    # cpu_print(10**7)
    # print("cpu vector add time " + str(time() - start_cpu))

if __name__ == "__main__":
    main()